package zuoye.ershouche.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zuoye.ershouche.entity.CarInfo;
import zuoye.ershouche.entity.dto.CarInfoDTO;
import zuoye.ershouche.entity.dto.CarInfoUpdateDTO;
import zuoye.ershouche.mapper.CarImageMapper;
import zuoye.ershouche.mapper.CarInfoMapper;
import zuoye.ershouche.service.CarInfoService;

import java.util.Collections;
import java.util.List;

@Service
public class CarInfoServiceImpl implements CarInfoService {

    @Autowired
    CarInfoMapper carInfoMapper;

    @Autowired
    CarImageMapper carImageMapper;

    @Override
    @Transactional
    public int insertCarInfoWithCarImg(CarInfoDTO carInfoDTO, String[] srcs) {
        carImageMapper.insertCarImage(carInfoDTO.getUserId(), srcs);
        CarInfo carInfo = new CarInfo();
        BeanUtils.copyProperties(carInfoDTO, carInfo);
        carInfo.setCarPicture(srcs[0]);
        return carInfoMapper.insertCarInfo(carInfo);
    }

    @Override
    public int deleteCarInfoById(int id) {
        return carInfoMapper.deleteCarInfoById(id);
    }

    @Override
    public int updateCarInfo(CarInfoUpdateDTO carInfoUpdateDTO) {
        return carInfoMapper.updateCarInfo(carInfoUpdateDTO);
    }

    @Override
    public CarInfo getCarInfoById(int id) {
        return carInfoMapper.getCarInfoById(id);
    }

//    @Override
//    public List<CarInfo> getCarInfoList(int pageNum, int pageSize) {
//        return carInfoMapper.selectCarInfoList(pageNum, pageSize);
//    }
}
